import { http } from "@/utils/http";

// 证件列表返回类型
export type CertificateListResult = {
  code: number;
  msg: string;
  time: string;
  data: CertificateListData;
};

// 证件列表data数据类型
export type CertificateListData = {
  total: number;
  page: number;
  limit: number;
  list: CertificateListDataItem[];
};

// 证件列表data数据类型
export type CertificateListDataItem = {
  id: number;
  username: string;
  gender: string;
  unit: string;
  job: string;
  telephone: string;
  email: string;
  id_card: string;
  addres1: string;
  addres2: string;
  photo: string;
  status: number;
};

// 获取证件列表
export const getCertificateList = (
  page = 1,
  limit = 10,
  exhibitor_id?: number,
  certificate_type,
  username,
  telephone
) => {
  return http.request("get", "/api/certificate/list", {
    params: {
      page,
      limit,
      exhibitor_id,
      certificate_type,
      username,
      telephone
    }
  });
};

// 申请证件
export const applyCertificate = (data: any) => {
  return http.request("post", "/api/certificate/apply", {
    data
  });
};

// 获取证件详情
export const getCertificateDetail = (id: number, exhibitor_id?: number) => {
  return http.request("get", "/api/certificate/detail", {
    params: {
      id,
      exhibitor_id
    }
  });
};

// 更新证件
export const updateCertificate = (data: any) => {
  return http.request("post", "/api/certificate/update", {
    data
  });
};

// 更改证件状态
export const updateCertificateStatus = (
  id: number,
  exhibitor_id: number,
  status: number
) => {
  return http.request("post", "/api/certificate/changeStatus", {
    data: {
      id,
      exhibitor_id,
      status
    }
  });
};
